#include <iostream>
using namespace std;

// 1. 不要返回局部变量引用
// reference to stack memory associated with local variable 'a' returned [-Wreturn-stack-address]
// int &test01()
// {
//   int a = 10;

//   return a;
// }

// 2. 函数的调用可以作为左值
int& test02() {
  static int a = 10;
  return a;
}

int main(int argc, char const *argv[])
{
  // int &ref = test01();
  int &ref2 = test02();

  cout << "ref2 = " << ref2 << endl;
  cout << "ref2 = " << ref2 << endl;

  test02() = 1000;  // 若如果函数的返回值是引用，那么这个函数可以作为左值

  cout << "ref2 = " << ref2 << endl;
  
  return 0;
}